import '../helper/dioHelper.dart';

class SWXG {
  double H;
  double V;
  double W;
  double MaxP;
  double XNZ;
  double HSL;

  SWXG(this.H, this.V, this.W, this.MaxP, this.XNZ, this.HSL);
  SWXG.fromJson(Map<String, dynamic> json)
      : H = json["H"],
        V = json["V"] * 1.0,
        W = json["W"] * 1.0,
        MaxP = json["MaxP"] * 1.0,
        XNZ = json["XNZ"] * 1.0,
        HSL = json["HSL"] * 1.0;
  Map<String, dynamic> toJson() => {
        'H': H,
        'V': V,
        'W': W,
        'MaxP': MaxP,
        'XNZ': XNZ,
        'HSL': HSL,
      };
  static Future<bool> Add(SWXG x1) async {
    var response = await DioHelper.Post("/SWXG/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(SWXG x1) async {
    var response = await DioHelper.Post("/SWXG/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(SWXG x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/SWXG/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<SWXG?> Get(String h0) async {
    print(DioHelper.BaseUrl + "/DayData/GetSWXG?h0=" + h0);
    var response = await DioHelper.Get("/DayData/GetSWXG?h0=" + h0, {});

    if (response.statusCode == 200) return new SWXG.fromJson(response.data);
    return null;
  }

  static Future<List<SWXG>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/SWXG/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <SWXG>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new SWXG.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<SWXG>> GetAllList() async {
    var response = await DioHelper.Get("/SWXG/GetAllList", {});
    var list1 = <SWXG>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new SWXG.fromJson(x));
      }
    }
    return list1;
  }
}
